package com.westcom.vulb.logic;

import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.json.JSONException;
import org.json.JSONObject;

import com.westcom.vulb.network.http.VulbHttp;
import com.westcom.vulb.protocal.http.Response;

public class share extends BasicLogic 
{
	private static String invited_list = base_url+"web/invited_list";
	private static String invite_with_mail = base_url+"web/invite_with_mail";
	private static String invite_with_id = base_url+"web/invite_with_userid";
	
	public static share getInstanse()
	{
		return new share();
	}
	
	public Response getInvitedList(String sessionId)
	{
		MultipartEntityBuilder builder = MultipartEntityBuilder.create();
		builder.addTextBody("params", "");
		builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
		Response response = VulbHttp.post(invited_list,buildHeader(sessionId),builder.build());
		return response;
	}
	public Response InviteWithMail(String sessionId,int sheetId,String []mail)
	{
		JSONObject j = new JSONObject();
        try 
        {
        	j.put("sheetId", sheetId);
			j.put("mailAddresses", StringArray2JSONArray(mail));
		} catch (JSONException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.addTextBody("params", j.toString());
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        Response response = VulbHttp.post(invite_with_mail,buildHeader(sessionId),builder.build());
        return response;
	}
	public Response InviteWithId(String sessionId,int sheetId,int[]id)
	{
		JSONObject j = new JSONObject();
        try 
        {
        	j.put("sheetId", sheetId);
			j.put("userIds", intArray2JSONArray(id));
		} catch (JSONException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.addTextBody("params", j.toString());
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        Response response = VulbHttp.post(invite_with_id,buildHeader(sessionId),builder.build());
        return response;
	}
}
